package com.ruoyi.coffeemenu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.coffeemenu.domain.Coffeemenu;
import com.ruoyi.coffeemenu.service.ICoffeemenuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 咖啡菜单Controller
 * 
 * @author ruoyi
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/coffeemenu/coffeemenu")
public class CoffeemenuController extends BaseController
{
    @Autowired
    private ICoffeemenuService coffeemenuService;

    /**
     * 查询咖啡菜单列表
     */
    @PreAuthorize("@ss.hasPermi('coffeemenu:coffeemenu:list')")
    @GetMapping("/list")
    public TableDataInfo list(Coffeemenu coffeemenu)
    {
        startPage();
        List<Coffeemenu> list = coffeemenuService.selectCoffeemenuList(coffeemenu);
        return getDataTable(list);
    }

    /**
     * 导出咖啡菜单列表
     */
    @PreAuthorize("@ss.hasPermi('coffeemenu:coffeemenu:export')")
    @Log(title = "咖啡菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Coffeemenu coffeemenu)
    {
        List<Coffeemenu> list = coffeemenuService.selectCoffeemenuList(coffeemenu);
        ExcelUtil<Coffeemenu> util = new ExcelUtil<Coffeemenu>(Coffeemenu.class);
        util.exportExcel(response, list, "咖啡菜单数据");
    }

    /**
     * 获取咖啡菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('coffeemenu:coffeemenu:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(coffeemenuService.selectCoffeemenuByProductId(productId));
    }

    /**
     * 新增咖啡菜单
     */
    @PreAuthorize("@ss.hasPermi('coffeemenu:coffeemenu:add')")
    @Log(title = "咖啡菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Coffeemenu coffeemenu)
    {
        return toAjax(coffeemenuService.insertCoffeemenu(coffeemenu));
    }

    /**
     * 修改咖啡菜单
     */
    @PreAuthorize("@ss.hasPermi('coffeemenu:coffeemenu:edit')")
    @Log(title = "咖啡菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Coffeemenu coffeemenu)
    {
        return toAjax(coffeemenuService.updateCoffeemenu(coffeemenu));
    }

    /**
     * 删除咖啡菜单
     */
    @PreAuthorize("@ss.hasPermi('coffeemenu:coffeemenu:remove')")
    @Log(title = "咖啡菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(coffeemenuService.deleteCoffeemenuByProductIds(productIds));
    }
}
